home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / mx / events / UIEventDispatcher.as < prev   
Text File  |  2007-11-08  |  4KB  |  117 lines

  1. class mx.events.UIEventDispatcher extends mx.events.EventDispatcher
  2. {
  3.    static var keyEvents = {keyDown:1,keyUp:1};
  4.    static var loadEvents = {load:1,unload:1};
  5.    static var lowLevelEvents = {keyEvents:["addKeyEvents","removeKeyEvents"],loadEvents:["addLoadEvents","removeLoadEvents"]};
  6.    static var _fEventDispatcher = undefined;
  7.    function UIEventDispatcher()
  8.    {
  9.       super();
  10.    }
  11.    static function addKeyEvents(obj)
  12.    {
  13.       if(obj.keyHandler == undefined)
  14.       {
  15.          var _loc0_ = null;
  16.          var _loc1_ = obj.keyHandler = new Object();
  17.          _loc1_.owner = obj;
  18.          _loc1_.onKeyDown = mx.events.UIEventDispatcher._fEventDispatcher.onKeyDown;
  19.          _loc1_.onKeyUp = mx.events.UIEventDispatcher._fEventDispatcher.onKeyUp;
  20.       }
  21.       Key.addListener(obj.keyHandler);
  22.    }
  23.    static function removeKeyEvents(obj)
  24.    {
  25.       Key.removeListener(obj.keyHandler);
  26.    }
  27.    static function addLoadEvents(obj)
  28.    {
  29.       if(obj.onLoad == undefined)
  30.       {
  31.          obj.onLoad = mx.events.UIEventDispatcher._fEventDispatcher.onLoad;
  32.          obj.onUnload = mx.events.UIEventDispatcher._fEventDispatcher.onUnload;
  33.          if(obj.getBytesTotal() == obj.getBytesLoaded())
  34.          {
  35.             obj.doLater(obj,"onLoad");
  36.          }
  37.       }
  38.    }
  39.    static function removeLoadEvents(obj)
  40.    {
  41.       delete obj.onLoad;
  42.       delete obj.onUnload;
  43.    }
  44.    static function initialize(obj)
  45.    {
  46.       if(mx.events.UIEventDispatcher._fEventDispatcher == undefined)
  47.       {
  48.          mx.events.UIEventDispatcher._fEventDispatcher = new mx.events.UIEventDispatcher();
  49.       }
  50.       obj.addEventListener = mx.events.UIEventDispatcher._fEventDispatcher.__addEventListener;
  51.       obj.__origAddEventListener = mx.events.UIEventDispatcher._fEventDispatcher.addEventListener;
  52.       obj.removeEventListener = mx.events.UIEventDispatcher._fEventDispatcher.removeEventListener;
  53.       obj.dispatchEvent = mx.events.UIEventDispatcher._fEventDispatcher.dispatchEvent;
  54.       obj.dispatchQueue = mx.events.UIEventDispatcher._fEventDispatcher.dispatchQueue;
  55.    }
  56.    function dispatchEvent(eventObj)
  57.    {
  58.       if(eventObj.target == undefined)
  59.       {
  60.          eventObj.target = this;
  61.       }
  62.       this[eventObj.type + "Handler"](eventObj);
  63.       this.dispatchQueue(mx.events.EventDispatcher,eventObj);
  64.       this.dispatchQueue(this,eventObj);
  65.    }
  66.    function onKeyDown(Void)
  67.    {
  68.       this.owner.dispatchEvent({type:"keyDown",code:Key.getCode(),ascii:Key.getAscii(),shiftKey:Key.isDown(16),ctrlKey:Key.isDown(17)});
  69.    }
  70.    function onKeyUp(Void)
  71.    {
  72.       this.owner.dispatchEvent({type:"keyUp",code:Key.getCode(),ascii:Key.getAscii(),shiftKey:Key.isDown(16),ctrlKey:Key.isDown(17)});
  73.    }
  74.    function onLoad(Void)
  75.    {
  76.       if(this.__sentLoadEvent != true)
  77.       {
  78.          this.dispatchEvent({type:"load"});
  79.       }
  80.       this.__sentLoadEvent = true;
  81.    }
  82.    function onUnload(Void)
  83.    {
  84.       this.dispatchEvent({type:"unload"});
  85.    }
  86.    function __addEventListener(event, handler)
  87.    {
  88.       this.__origAddEventListener(event,handler);
  89.       var _loc3_ = mx.events.UIEventDispatcher.lowLevelEvents;
  90.       for(var _loc5_ in _loc3_)
  91.       {
  92.          if(mx.events.UIEventDispatcher[_loc5_][event] != undefined)
  93.          {
  94.             var _loc2_ = _loc3_[_loc5_][0];
  95.             mx.events.UIEventDispatcher._loc2_(this);
  96.          }
  97.       }
  98.    }
  99.    function removeEventListener(event, handler)
  100.    {
  101.       var _loc6_ = "__q_" + event;
  102.       mx.events.EventDispatcher._removeEventListener(this[_loc6_],event,handler);
  103.       if(this[_loc6_].length == 0)
  104.       {
  105.          var _loc2_ = mx.events.UIEventDispatcher.lowLevelEvents;
  106.          for(var _loc5_ in _loc2_)
  107.          {
  108.             if(mx.events.UIEventDispatcher[_loc5_][event] != undefined)
  109.             {
  110.                var _loc3_ = _loc2_[_loc5_][1];
  111.                mx.events.UIEventDispatcher[_loc2_[_loc5_][1]](this);
  112.             }
  113.          }
  114.       }
  115.    }
  116. }
  117.